﻿<%@ page language="java" import="com.newcrm.config.Const,com.newcrm.util.Util,com.newcrm.bean.*,java.util.List,java.util.Map" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
  User user = (User) session.getAttribute("user");
  Map<Integer, CompanyInfo> companys = (Map<Integer, CompanyInfo>) application.getAttribute(Const.APPLICATION_COMPANYS);
  CompanyInfo companyInfo = companys.get(Integer.valueOf(user.companyId));
  List<Map<String, Object>> dealCategory = companyInfo.dealCategorys;
  List<User> users = companyInfo.users;
%>
<div class="searchbar" id="searchbar">
  <a class="closebtn" href="#" id="adv-search-close"><i class="fa fa-times"></i></a>
  <h1><i class="fa fa-search"></i> 点击下面的字段设置搜索条件</h1>
  <ul>
    <li>
      <div class='popbox'>
        <a class='open' href='#'>名称</a>
        <div class='collapse'>
          <div class='box'>
            <div class='arrow'></div><div class='arrow-border'></div>
            <form name="name" valueType="<%=Const.FIELD_TYPE_TEXT%>" id="search_condition_name_form">
              <p class="fields">
                <input class="filter" name="name" type="text" id="search_condition_name" /> <input name="commit" class="button" type="submit" value="查找" />
                <small>提示：输入销售机会的名称</small>
              </p>
            </form>
          </div>
        </div>
      </div>
    </li>
    <% if (dealCategory != null && dealCategory.size() > 0) {%>
    <li>
      <div class='popbox'>
        <a class='open' href='#'>分类</a>
        <div class='collapse'>
          <div class='box'>
            <div class='arrow'></div><div class='arrow-border'></div>
            <form name="CategoryId" valueType="<%=Const.FIELD_TYPE_SELECT%>">
              <p class="fields">
                <select name="CategoryId">
                  <option value="0">全部</option>
                 <%for (Map<String, Object> cate:dealCategory) { %>
                  <option value="<%=cate.get("DealCategoryId")%>"><%=cate.get("DealCategoryName")%></option>
                 <%}%>
                </select> <input name="commit" class="button" type="submit" value="查找" />
              </p>
            </form>
          </div>
        </div>
      </div>
    </li>
    <%}%>
    <% if (user.isAdmin || user.isGroupAdmin) {%>
    <li>
      <div class='popbox'>
        <a class='open' href='#'>负责人</a>
        <div class='collapse'>
          <div class='box'>
            <div class='arrow'></div><div class='arrow-border'></div>
            <form name="ResponsibleUserId" valueType="<%=Const.FIELD_TYPE_SELECT%>">
              <p class="fields">
                <select name="ResponsibleUserId">
                  <option value="*">所有人</option>
                  <option value="<%=user.userId%>">我</option>
                 <%for (User u : users) {
                  if (u.userId.equals(user.userId)) {
                    continue;
                  }
                  if (!companyInfo.isGroupAdmin(user, u.groupId)) {
                    continue;
                  }%>
                  <option value="<%=u.userId%>"><%=Util.HTMLEncode(u.name)%></option>
                <%}%>
                </select> <input name="commit" class="button" type="submit" value="查找" />
              </p>
            </form>
          </div>
        </div>
      </div>
    </li>
    <%}%>

    <li>
      <div class='popbox'>
        <a class='open' href='#'>创建时间</a>
        <div class='collapse'>
          <div class='box'>
            <div class='arrow'></div><div class='arrow-border'></div>
            <form name="CreateDate" valueType="<%=Const.FIELD_TYPE_DATE%>">
              <p class="fields">
                <input type="text" id="CreateDate" class="filter daterangepickerinput" value="" /> <input name="commit" class="button" type="submit" value="查找" />
              </p>
            </form>
          </div>
        </div>
      </div>
    </li>

    <li>
      <div class='popbox'>
        <a class='open' href='#'>成交时间</a>
        <div class='collapse'>
          <div class='box'>
            <div class='arrow'></div><div class='arrow-border'></div>
            <form name="WonDate" valueType="<%=Const.FIELD_TYPE_DATE%>">
              <p class="fields">
                <input type="text" id="WonDate" class="filter daterangepickerinput" value="" /> <input name="commit" class="button" type="submit" value="查找" />
              </p>
            </form>
          </div>
        </div>
      </div>
    </li>
<%
  List<Map<String, Object>> fields = (List<Map<String, Object>>) request.getAttribute("fields");
  if (fields != null) {
    for (Map<String, Object> field:fields) {
      int valueType = Util.str2Int(field.get("ValueType"));
      String initValue = (String) field.get("InitValue");
%>
    <li>
      <div class='popbox'>
        <a class='open' href='#'><%=Util.HTMLEncode((String)field.get("DealFieldName"))%></a>
        <div class='collapse'>
          <div class='box'>
            <div class='arrow'></div><div class='arrow-border'></div>
            <form name="<%=Const.FIELD_KEY%><%=field.get("DealFieldId")%>" valueType="<%=valueType%>">
              <p class="fields">
                <%if (valueType == Const.FIELD_TYPE_DATE) {%>
                <span><%=Util.HTMLEncode((String)field.get("DealFieldName"))%>：</span><input class="daterangepickerinput" id="<%=Const.FIELD_KEY%><%=field.get("DealFieldId")%>" name="<%=Const.FIELD_KEY%><%=field.get("DealFieldId")%>" type="text" />
                <input name="commit" class="button" type="submit" value="查找" />
                <%} else if (valueType == Const.FIELD_TYPE_SELECT || valueType == Const.FIELD_TYPE_CHECKBOX) {%>
                <select>
                <option value="">请选择</option>
               <%
                if (initValue != null && initValue.length() > 0) {
                  String[] arr = initValue.split(",");
                  for (String v:arr) { %>
                <option value="<%=Util.HTMLEncode(v)%>"><%=Util.HTMLEncode(v)%></option>
               <%  }
                }%>
               </select> <input name="commit" class="button" type="submit" value="查找" />
               <%} else if (valueType == Const.FIELD_TYPE_NUMBER) { %>
                <input class="filter3" type="text" /> <span>至</span> <input class="filter3" type="text" /> <input name="commit" class="button" type="submit" value="查找" />
                <%} else {%>
                <input class="filter" type="text" /> <input name="commit" class="button" type="submit" value="查找" />
                <%}%>
              </p>
            </form>
          </div>
        </div>
      </div>
    </li>
<%
    }
  }
%>
  </ul>
  <div class="clearfix"></div>
  <div class="searchitem" id="page_filter_selected"></div>
</div>